<?php
/**
 * The Template for displaying all single posts
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */

get_header(); 
//get video cat:
$cats=get_the_category($post_id);
//t($cats);
$backlink=home_url();
$isbanket=false;
$ischungket=false;

if(count($cats)>0){
	foreach($cats as $k=>$v){
		if($v->slug=='vongchungket'){
			$backlink=home_url('/category/vongchungket');
			$isbanket=true;
			break;
		}
		else if($v->slug=='vongbanket'){
			$backlink=home_url('/category/vongchungket');
			$ischungket=true;
			break;
		}
		else{
			$backlink=home_url('/category/'.$v->slug);
		}
	}
}
$optionfb=get_option('bigckool_option_fb');

?>

	<div class='videodetail_side' itemscope="" itemtype="http://schema.org/Article">
	<div style="display:none">
		<div itemprop="name"><?php the_title()?></div>
		<div itemprop="description"><?php the_title()?></div>
	</div>
                        
           <?php if ( have_posts() ) : the_post();	
				$prev=get_permalink(get_adjacent_post(false,'',false)); 
				if($prev == get_permalink()) {
					//get last link
					$prev='';
				}
				$next=get_permalink(get_adjacent_post(false,'',true)); 
				if($next == get_permalink()) {
					//get first link
					$next='';
				} 
			?>
                        <div class='side_content'>
                            <img src='<?php echo get_template_directory_uri()?>/img/header_videoduthi.png' class='title' alt=''/>
                            
                            <div id='back_button'>
                                    <a href='<?php echo $backlink?>'>
                                        <img src='<?php echo get_template_directory_uri()?>/img/video_back.png' alt=''/>
                                    </a>
                            </div>
                            
                            <?php if(!empty($next)){?>
                            <div id='next_button'>
                                    <a href='<?php echo $next?>'>
                                        <img src='<?php echo get_template_directory_uri()?>/img/video_next.png' alt=''/>
                                    </a>
                            </div>
                            <?php }?>
                            <?php if(!empty($prev)){?>
                            <div id='pre_button'>
                                    <a href='<?php echo $prev?>'>
                                        <img src='<?php echo get_template_directory_uri()?>/img/video_pre.png' alt=''/>
                                    </a>
                            </div>
                            <?php }?>
                            <div class='video_detail'><?php the_content( );?></div>
			
                      		<div  id="votecontent">                      
           

       					 
		
	<?php if(!$isbanket && !$ischungket && $optionfb['like_enable']){
			$isVoted= bigckool_isVoted($post->ID);
			$count=get_post_meta($post->ID,'votecount',1);
			
			if(!$isVoted){
		?>
                                <div id='vote_button'>
                                    
	                                <span style='font-family: MyriadPro_Bold;text-transform: uppercase;color: #4864b4;'>Bình chọn bằng cách nhấn </span>
	
	                                <div style='position: absolute;top: -2px;width: 50px;height: 20px;margin-left: 210px;' onclick="postVote()">
	                                    
	                                    <div id="localLike" style='width: 50px;height: 20px;overflow: hidden;margin-bottom: 1px;cursor:pointer;'>
	                                    	<img width="47px" src='<?php echo get_template_directory_uri()?>/img/button_like.png' alt=''/>
                                    	</div>
	                                </div>
	
	                                <div id="countcontent" style='opacity:1;position: absolute;left: 260px;top:-10px'>
	                                    <span style='position: relative;top: 6px;left: 4px;'>  
	                                        <img src='<?php echo get_template_directory_uri()?>/img/like_box_head.png' />
	                                    </span>
	                                    <span id="numberoflike" style='background:url(<?php echo get_template_directory_uri()?>/img/like_box_mid.jpg) repeat-x;padding: 3px 10px;color: #999;font-size:9pt'><?php echo $count?></span>
	                                    <span style='position: relative;top: 6px;left: -4px;'>  
	                                        <img src='<?php echo get_template_directory_uri()?>/img/like_box_bottom.png' />
	                                    </span>
	                                   
	                                </div>

	                                <div id="countLoading" style='position: absolute;left: 267px;top:-2px; display: none;'>
	                                	<img  src='<?php echo get_template_directory_uri()?>/img/loader.gif' style='width:20px;margin-left:5px;'/>
	                                </div>
									<div id="share_button" style='position: absolute;top: -3px;left:305px;cursor:pointer;'>
	                                    <img src='<?php echo get_template_directory_uri()?>/img/sharebt.png' alt=''/>
								 		<img style="display:none" src='<?php echo get_template_directory_uri()?>/img/70x70.png' alt=''/>
	                                </div>
	                                
	                                    
	                                    
	                            </div>
                                <?php }else{?> 
                                   <div id='voted_button'>
                                   	<span id='liked_button'>Bạn <span id='ortherlikecount'><?php echo $count>1?"và ".($count-1)." người":""?></span> đã bình chọn</span>
                                   </div>
                                   <span id="share_button" style='position: relative;top: 5px;cursor:pointer;z-index:14;margin-left: 10px;'>
	                                    <img src='<?php echo get_template_directory_uri()?>/img/sharebt.png' alt=''/>
								 		<img style="display:none" src='<?php echo get_template_directory_uri()?>/img/70x70.png' alt=''/>
	                                </span>
                                   
                            <?php } }?>
                           
                            </div>
                             
                            
                            
                           
							
							<div id='singer_info'>
                                <div id='singer_name'>Họ và tên: <span style='color:#b81f1f'><?php echo post_custom('fullname')?></div>
                                <div id='singer_dob'>Năm sinh: <span style='color:#b81f1f'><?php echo post_custom('date-of-birth')?></div>
                                <div id='singer_nonumber'>Mã số dự thi: <span style='color:#b81f1f'><?php echo post_custom('code')?></div>
                                <div id='singer_song'>Tên bài hát: <span style='color:#b81f1f'><?php echo post_custom('songname')?></div>
                                <div id='singer_musician'>Nhạc sĩ: <span style='color:#b81f1f'><?php echo post_custom('composer')?></div>
                            </div>
                        </div>
                        
            <script>

            function addShareEvent()
            {
            	$('#share_button').on('click', function(e){
					e.preventDefault();
					FB.ui(
					{
					method: 'feed',
					name: 'BigC Kool Idol',
					link: fbplugin.selfurl,
					picture: 'http://itk.vn/wp-content/themes/bigckool/img/70x70.png',
					caption: '<?php the_title()?>',
					description: 'Hãy bình chọn cho tôi',
					message: ''
					});
				});
        	}

        	function postVote()
        	{
        		<?php if (bigckool_alreadyLogin(true, $post->ID)) {?>
        		$('#countLoading').show();
        		$('#countcontent').hide();
				jQuery.post(
				    '<?php echo admin_url('admin-ajax.php'); ?>', 
				    {
				        'action': 'submitvote',
				        'data':   '<?php echo $post->ID?>'
				    }, 
				    function(response){
				       //$('votecontent').html(response);
				       
				       $('#countLoading').hide();
				       if(response!=null && response=="success0")
				       {
				       	showLikedWithCount(<?php echo $count?>);
				       	addShareEvent();
				    	}
				       else{
							alert("Server đang bận hoặc trình duyệt của bạn không tương thích. Vui lòng thử lại vào lúc khác hoặc chuyển sang trình duyệt khác.");
							$('#countcontent').show();
					       }
				    
				    }
				);
				<?php } else {?>
					alert('Không xác nhận được tài khoản Facebook của bạn. Vui lòng đăng nhập lại để bình chọn hoặc thay đổi trình duyệt');
				<?php }?>
        	}
			$(document).on("facebook:ready", function(){
				if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){					
					$('#numberoflike').css('padding','5px 10px');
				}
				addShareEvent();
			});
				
			</script>

<?php endif;?>
                    </div>
			
					

<?php
get_footer();
?>